<extend name="Public/base"/>

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>商品管理</h2>
	</div>
	<div class="tools auth-botton">
        <a class="btn" href="{:U('createGoods')}">新 增</a>
        <button class="btn ajax-post" url="{:U('changeStatus?method=resumegoods')}" target-form="ids">启 用</button>
        <button class="btn ajax-post" url="{:U('changeStatus?method=forbidgoods')}" target-form="ids">禁 用</button>
        <button class="btn ajax-post confirm" url="{:U('changeStatus?method=deletegoods')}" target-form="ids">删 除</button>
	</div>
	<!-- 按钮工具栏 -->
	<div class="cf">
		<!-- 高级搜索 -->
		<div class="search-form fr cf">
			<div class="sleft">
				<div class="drop-down">
					<span id="sch-sort-txt" class="sort-txt" data="{$status}"><if condition="get_status_title($status) eq ''">所有<else/>{:get_status_title($status)}</if></span>
					<i class="arrow arrow-down"></i>
					<ul id="sub-sch-menu" class="nav-list hidden">
						<li><a href="javascript:;" value="">所有</a></li>
						<li><a href="javascript:;" value="1">正常</a></li>
						<li><a href="javascript:;" value="0">禁用</a></li>
					</ul>
				</div>
				<input type="text" name="goodsname" class="search-input" value="{:I('goodsname')}" placeholder="请输入商品名称">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('goods/index?id='.$id)}"><i class="btn-search"></i></a>
			</div>
		</div>
	</div>
	<div class="tab-wrap">
		<ul id="typetab" class="tab-nav nav">
			<volist name="typelist" id="type">
				<li <eq name="id" value="$type[id]"> class="current"</eq>><a href="{:U('?id='.$type[id])}">{$type.name}</a></li>
			</volist>
		</ul>
	</div>
	<!-- 数据列表 -->
    <div class="data-table table-striped">
	    <table class="">
	    	<thead>
	    		<tr>
	    			<th class="row_selected row-selected"><input type="checkbox" class="check-all"></th>
	    			<th class="">ID</th>
	    			<th class="">排序</th>
	    			<!-- <th class="">商品编号</th> -->
	    			<th class="">商品名称</th>
	    			<th class="">备注</th>
	    			<th class="">状态</th>
	    			<th class="">操作</th>
	    		</tr>
	    	</thead>
	    	<tbody>
	    		<notempty name="_list">
	    		<volist name="_list" id="vo">
	    		<tr>
	    			<td><input type="checkbox" class="ids" name="id[]" value="{$vo.id}"></td>
	    			<td>{$vo.id}</td>
	    			<td>{$vo.sort}</td>
	    			<!-- <td>{$vo.num}</td> -->
	    			<td>{$vo.name}</td>
	    			<td>{$vo.remark}</td>
	    			<td>{$vo.status_text}</td>
	    			<td>
	    			<eq name="vo.status" value="1">
					<a href="{:U('Goods/changeStatus?method=forbidgoods&id='.$vo['id'])}" class="ajax-get">禁用</a>
					<else/>
					<a href="{:U('Goods/changeStatus?method=resumegoods&id='.$vo['id'])}" class="ajax-get">启用</a>
					</eq>
					<a href="{:U('Goods/goodsspec?gid='.$vo['id'])}">规格</a>
					<a href="{:U('Goods/edit?id='.$vo['id'])}">编辑</a>
	    			<a href="{:U('Goods/changeStatus?method=deletegoods&id='.$vo['id'])}" class="confirm ajax-get">删除</a></td>
	    		</tr>
	    		</volist>
	    		<else/>
	    		<td colspan="7" class="text-center">暂时还没有数据！</td>
	    		</notempty>
	    	</tbody>
	    </table>
	    <div class="page">
	    	{$_page}
	    </div>
    </div>
</block>

<block name="script">
	<script type="text/javascript">
	//搜索功能
		$("#search").click(function(){
			var url = $(this).attr('url');
			var status = $("#sch-sort-txt").attr("data");
	        var query  = $('.search-form').find('input').serialize();
	        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
	        query = query.replace(/^&/g,'');
			if(status != ''){
				query = 'status=' + status + "&" + query;
	        }
	        if( url.indexOf('?')>0 ){
	            url += '&' + query;
	        }else{
	            url += '?' + query;
	        }
			window.location.href = url;
		});

		/* 状态搜索子菜单 */
		$(".search-form").find(".drop-down").hover(function(){
			$("#sub-sch-menu").removeClass("hidden");
		},function(){
			$("#sub-sch-menu").addClass("hidden");
		});
		$("#sub-sch-menu li").find("a").each(function(){
			$(this).click(function(){
				var text = $(this).text();
				$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
				$("#sub-sch-menu").addClass("hidden");
			})
		});

		//回车自动提交
	    $('.search-form').find('input').keyup(function(event){
	        if(event.keyCode===13){
	            $("#search").click();
	        }
	    });


    //导航高亮
    highlight_subnav('{:U('Goods/index')}');
	</script>
</block>